﻿namespace TradePublish
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Net;
    using System.Windows.Forms;
    using TradePublish.Service.impl;
    using System.Collections.Generic;
    using TradePublish.Entity;
    using TradePublish.Service;
    using TradePublish.Common;

    public class Form1 : Form
    {
        private Button button1;
        private Button button2;
        private TextBox textBox1;
        private Button button3;
        private IContainer components = null;

        public Form1()
        {
            this.InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button3 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(649, 12);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(49, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(574, 60);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 1;
            this.button2.Text = "button2";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(150, 61);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(312, 21);
            this.textBox1.TabIndex = 2;
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(483, 116);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 3;
            this.button3.Text = "button3";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(710, 487);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
        }

        private static bool SaveBinaryFile(WebResponse response, string FileName)
        {
            bool flag = true;
            byte[] buffer = new byte[0x400];
            try
            {
                int num;
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                Stream stream = File.Create(FileName);
                Stream responseStream = response.GetResponseStream();
                do
                {
                    num = responseStream.Read(buffer, 0, buffer.Length);
                    if (num > 0)
                    {
                        stream.Write(buffer, 0, num);
                    }
                }
                while (num > 0);
                stream.Close();
                responseStream.Close();
            }
            catch
            {
                flag = false;
            }
            return flag;
        }

        public static bool SavePhotoFromUrl(string FileName, string Url)
        {
            bool flag = false;
            WebResponse response = null;
            Stream responseStream = null;
            try
            {
                response = ((HttpWebRequest) WebRequest.Create(Url)).GetResponse();
                responseStream = response.GetResponseStream();
                if (!response.ContentType.ToLower().StartsWith("text/"))
                {
                    flag = SaveBinaryFile(response, FileName);
                }
            }
            catch (Exception exception)
            {
                string str = exception.ToString();
            }
            return flag;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            BingManager b = new BingManager();
            List<String> list = b.graspUrl(this.textBox1.Text);
            for (int i = 0; i < list.Count; i++)
            {
                MessageBox.Show(list[i]);
            }
            int com = 0;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //List<TradeNameSplit> tradeNames = null;
                                
            //tradeNames = Utils.splitTradeName("京东商城 360BUY.COM");
                                
            //AntiSearchTMManager antiSearchTMManager = new AntiSearchTMManager();
            //antiSearchTMManager.tradePublishId = 12653309;
            //antiSearchTMManager.tradeNames = tradeNames;//待反查的商标名（已拆分）
            //antiSearchTMManager.classNo =45;//国际分类号
            //antiSearchTMManager.regNo = "9701056";//待查商标的注册号，用来排除自身用的
            //antiSearchTMManager.applyUserNameZh = tradePublishs[j].applyUserName;
            //List<AntiSearchResult> results = null;
            //List<String[]> details = new List<string[]>();
            //while (true)
            //{
            //    try
            //    {
            //        results = antiSearchTMManager.antiSearch(details);
            //        break;
            //    }
            //    catch (Exception e)
            //    {
            //        log.Error(id + "反查发生了异常.", e);
            //        Thread.Sleep(1000);
            //    }
            //} 
        }
    }
}

